<html>
<head><meta charset="utf-8"><title>Something stalls in the type inference? · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Something.20stalls.20in.20the.20type.20inference.3F.html">Something stalls in the type inference?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="232315866"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Something%20stalls%20in%20the%20type%20inference%3F/near/232315866" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Something.20stalls.20in.20the.20type.20inference.3F.html#232315866">(Mar 29 2021 at 18:43)</a>:</h4>
<p>I am seeing the following in the profilere output when typing at the top level in <a href="http://apply_change.rs">apply_change.rs</a>:</p>
<div class="codehilite"><pre><span></span><code> 2183ms - handle_semantic_tokens_full_delta
     2183ms - highlight
         2090ms - infer:wait @ per_query_memory_usage
             2090ms - infer_query
                    2ms - crate_def_map:wait (17088 calls)
                    0ms - generic_params_query (1 calls)
                 2088ms - ???
</code></pre></div>



<a name="232315976"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Something%20stalls%20in%20the%20type%20inference%3F/near/232315976" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Something.20stalls.20in.20the.20type.20inference.3F.html#232315976">(Mar 29 2021 at 18:44)</a>:</h4>
<p>Anyone has ideas about what that 2 semonds of ??? might be doing?</p>



<a name="232316236"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Something%20stalls%20in%20the%20type%20inference%3F/near/232316236" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Something.20stalls.20in.20the.20type.20inference.3F.html#232316236">(Mar 29 2021 at 18:45)</a>:</h4>
<p>What's <code>per_query_memory_usage</code> doing there?</p>



<a name="232316501"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Something%20stalls%20in%20the%20type%20inference%3F/near/232316501" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Something.20stalls.20in.20the.20type.20inference.3F.html#232316501">(Mar 29 2021 at 18:47)</a>:</h4>
<p>hm, I suspect that might actually be the ansewer? Thanks for reading the paster text to me, <span class="user-mention" data-user-id="203546">@Laurențiu</span> !</p>



<a name="232316537"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Something%20stalls%20in%20the%20type%20inference%3F/near/232316537" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Something.20stalls.20in.20the.20type.20inference.3F.html#232316537">(Mar 29 2021 at 18:47)</a>:</h4>
<p>I suspect it just expands the macros</p>



<a name="232318687"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Something%20stalls%20in%20the%20type%20inference%3F/near/232318687" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Something.20stalls.20in.20the.20type.20inference.3F.html#232318687">(Mar 29 2021 at 19:03)</a>:</h4>
<p>Wait, no, this is infer, it happens after expand</p>



<a name="232319757"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Something%20stalls%20in%20the%20type%20inference%3F/near/232319757" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Something.20stalls.20in.20the.20type.20inference.3F.html#232319757">(Mar 29 2021 at 19:11)</a>:</h4>
<p>Did you run the memory usage command?</p>



<a name="232320701"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Something%20stalls%20in%20the%20type%20inference%3F/near/232320701" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Something.20stalls.20in.20the.20type.20inference.3F.html#232320701">(Mar 29 2021 at 19:18)</a>:</h4>
<p>No, I am typing in the file that implements this command</p>



<a name="232321317"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Something%20stalls%20in%20the%20type%20inference%3F/near/232321317" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Something.20stalls.20in.20the.20type.20inference.3F.html#232321317">(Mar 29 2021 at 19:22)</a>:</h4>
<p>Will come back to this tomorrow, unless someone from other timezone beats me to it. This is as far as I've gone:</p>
<p><a href="/user_uploads/4715/mdjWPSQGFh0FLBDpiDUukgcr/image.png">image.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/mdjWPSQGFh0FLBDpiDUukgcr/image.png" title="image.png"><img src="/user_uploads/4715/mdjWPSQGFh0FLBDpiDUukgcr/image.png"></a></div>



<a name="232321701"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Something%20stalls%20in%20the%20type%20inference%3F/near/232321701" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Something.20stalls.20in.20the.20type.20inference.3F.html#232321701">(Mar 29 2021 at 19:25)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133169">matklad</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Something.20stalls.20in.20the.20type.20inference.3F/near/232320701">said</a>:</p>
<blockquote>
<p>No, I am typing in the file that implements this command</p>
</blockquote>
<p>Oh, right</p>



<a name="232326249"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Something%20stalls%20in%20the%20type%20inference%3F/near/232326249" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Something.20stalls.20in.20the.20type.20inference.3F.html#232326249">(Mar 29 2021 at 19:56)</a>:</h4>
<p>I've definitely seen this function take a while before, yeah</p>



<a name="232327942"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Something%20stalls%20in%20the%20type%20inference%3F/near/232327942" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Something.20stalls.20in.20the.20type.20inference.3F.html#232327942">(Mar 29 2021 at 20:08)</a>:</h4>
<p>The big issue is not the time per se, but the fact that the works seems uncancellable</p>



<a name="232328314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Something%20stalls%20in%20the%20type%20inference%3F/near/232328314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Something.20stalls.20in.20the.20type.20inference.3F.html#232328314">(Mar 29 2021 at 20:10)</a>:</h4>
<p>On the positeve side, thacking this made me realize that our existing profile calls can be used to decect missing cancellation: <a href="https://github.com/rust-analyzer/rust-analyzer/pull/8244">https://github.com/rust-analyzer/rust-analyzer/pull/8244</a></p>



<a name="232329210"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Something%20stalls%20in%20the%20type%20inference%3F/near/232329210" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Something.20stalls.20in.20the.20type.20inference.3F.html#232329210">(Mar 29 2021 at 20:17)</a>:</h4>
<p>yeah, saw that PR, really nice trick!</p>



<a name="232434365"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Something%20stalls%20in%20the%20type%20inference%3F/near/232434365" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Something.20stalls.20in.20the.20type.20inference.3F.html#232434365">(Mar 30 2021 at 14:28)</a>:</h4>
<p>stand-alone repro: <a href="https://github.com/rust-analyzer/rust-analyzer/issues/8263">https://github.com/rust-analyzer/rust-analyzer/issues/8263</a></p>



<a name="232435286"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Something%20stalls%20in%20the%20type%20inference%3F/near/232435286" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Something.20stalls.20in.20the.20type.20inference.3F.html#232435286">(Mar 30 2021 at 14:32)</a>:</h4>
<p><span class="user-mention" data-user-id="129457">@Florian Diebold</span> do you want to look into that?</p>



<a name="232444093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Something%20stalls%20in%20the%20type%20inference%3F/near/232444093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Something.20stalls.20in.20the.20type.20inference.3F.html#232444093">(Mar 30 2021 at 15:19)</a>:</h4>
<p>hmm. that's one of those functions that will be mostly replaced with a Chalk equivalent</p>



<a name="232444359"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Something%20stalls%20in%20the%20type%20inference%3F/near/232444359" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Something.20stalls.20in.20the.20type.20inference.3F.html#232444359">(Mar 30 2021 at 15:21)</a>:</h4>
<p>so I wouldn't want to put much time into that right now</p>



<a name="232444638"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Something%20stalls%20in%20the%20type%20inference%3F/near/232444638" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Something.20stalls.20in.20the.20type.20inference.3F.html#232444638">(Mar 30 2021 at 15:23)</a>:</h4>
<p>Makes sense. I looked into this a bit more, looks like the loop in </p>
<div class="codehilite"><pre><span></span><code>    fn resolve_obligations_as_possible(&amp;mut self) {
        let obligations = mem::replace(&amp;mut self.obligations, Vec::new());
        for obligation in obligations {
</code></pre></div>
<p>is queadratic for this particular case</p>



<a name="232444695"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Something%20stalls%20in%20the%20type%20inference%3F/near/232444695" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Something.20stalls.20in.20the.20type.20inference.3F.html#232444695">(Mar 30 2021 at 15:23)</a>:</h4>
<p>We accumulate 500 obligations or so</p>



<a name="232444730"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Something%20stalls%20in%20the%20type%20inference%3F/near/232444730" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Something.20stalls.20in.20the.20type.20inference.3F.html#232444730">(Mar 30 2021 at 15:23)</a>:</h4>
<p>ok, that's not so great and will not be impacted by the Chalk move</p>



<a name="232444824"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Something%20stalls%20in%20the%20type%20inference%3F/near/232444824" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Something.20stalls.20in.20the.20type.20inference.3F.html#232444824">(Mar 30 2021 at 15:24)</a>:</h4>
<p>rustc solves this with the obligation forest data structure</p>



<a name="232444862"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Something%20stalls%20in%20the%20type%20inference%3F/near/232444862" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Something.20stalls.20in.20the.20type.20inference.3F.html#232444862">(Mar 30 2021 at 15:24)</a>:</h4>
<p>I guess it's a few obligations for each of those macro calls? the problem might be that we don't manage to solve any of them</p>



<a name="232445067"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Something%20stalls%20in%20the%20type%20inference%3F/near/232445067" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Something.20stalls.20in.20the.20type.20inference.3F.html#232445067">(Mar 30 2021 at 15:26)</a>:</h4>
<p>but also, if nothing changes we should be able to reuse a cached solution, if we're not then something may be wrong with that as well</p>



<a name="232445240"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Something%20stalls%20in%20the%20type%20inference%3F/near/232445240" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Something.20stalls.20in.20the.20type.20inference.3F.html#232445240">(Mar 30 2021 at 15:27)</a>:</h4>
<p>Another bit: a lot of paths in that function are unresolved.</p>



<a name="232445266"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Something%20stalls%20in%20the%20type%20inference%3F/near/232445266" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Something.20stalls.20in.20the.20type.20inference.3F.html#232445266">(Mar 30 2021 at 15:27)</a>:</h4>
<p>So we might hit some bad case around unknown type?</p>



<a name="232452451"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Something%20stalls%20in%20the%20type%20inference%3F/near/232452451" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Something.20stalls.20in.20the.20type.20inference.3F.html#232452451">(Mar 30 2021 at 16:10)</a>:</h4>
<p>yes, probably</p>



<a name="232463526"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Something%20stalls%20in%20the%20type%20inference%3F/near/232463526" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Something.20stalls.20in.20the.20type.20inference.3F.html#232463526">(Mar 30 2021 at 17:19)</a>:</h4>
<p>Also, the thing reproduces if run "expand macros recursively" and manually paste the output (removing noisy format! calls mnaually), so this is unrelated to macros</p>



<a name="232814902"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Something%20stalls%20in%20the%20type%20inference%3F/near/232814902" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Something.20stalls.20in.20the.20type.20inference.3F.html#232814902">(Apr 01 2021 at 19:51)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust-analyzer/issues/8285">rust-analyzer#8285</a></p>



<a name="232815007"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Something%20stalls%20in%20the%20type%20inference%3F/near/232815007" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Something.20stalls.20in.20the.20type.20inference.3F.html#232815007">(Apr 01 2021 at 19:52)</a>:</h4>
<p>but yeah that's a lot of obligations that we never manage to solve</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>